package com.lc.demo.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lc.demo.bean.*;
import com.lc.demo.result.ResponseMessage;
import com.lc.demo.service.*;
import com.lc.demo.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.*;


@CrossOrigin
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private StudentService studentService;

    @PostMapping(value = "/login")
    public ResponseMessage login(@RequestBody Teacher teacher) {
        Teacher teacher1 = teacherService.login(teacher.getUsername(), teacher.getPassword());
        if (teacher1 != null) {
            return ResponseMessage.successWithMessage(teacher1.getUsername());
        } else {
            return ResponseMessage.errorWithMessage("用户名或密码错误");
        }
    }



   /* @Autowired
    private ClassgradeService classgradeService;*/


    @Autowired
    private CourseService courseService;



    //查询签到人数
    @PostMapping(value = "/findSignPersonList")
    public ResponseMessage findSignPersonList(@RequestBody Map<String,Object> map) {
       Course course=new Course();

        BeanUtil.copyProperties2Bean(map,course);
        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        PageHelper.startPage(pageNum, pageSize);
        List<SignPerson> signPersonList = courseService.findSignPerson(course);
        PageInfo<SignPerson> page = new PageInfo<>(signPersonList);
        return ResponseMessage.successWithData(page);
    }



    @Autowired
    private  LeavetableService leavetableService;

    //查询审核列表
    @PostMapping(value = "/findLeaveList")
    public ResponseMessage findLeaveList(@RequestBody   Map<String,Object> map) {
        Leavetable leavetable =new Leavetable();
        BeanUtil.copyProperties2Bean(map,leavetable);
        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        PageHelper.startPage(pageNum, pageSize);
        List<Leavetable> leavetableList = leavetableService.findLeaveList(leavetable);
        PageInfo<Leavetable> page = new PageInfo<>(leavetableList);
        return ResponseMessage.successWithData(page);
    }


    //请假审核接口
    @PostMapping(value = "/reviewLeave")
    public ResponseMessage reviewLeave(@RequestBody Leavetable leavetable) {
        // String username = (String) session.getAttribute("loginUser");
       leavetableService.reviewLeave(leavetable);
        return ResponseMessage.success();
    }

/*    @Autowired
    private  SigninService signinService;*/


}
